package chapter10.practice12;

/**
 * 用匿名内部类实现 练习7
 * Created by yangliwei on 2017/10/21.
 */
public class SimpleClass {
    private String item;

    private void f() {
        System.out.println("I'm called");
    }

    public void changeFieldAndCallMethod() {
        //因为这里没有接口或父类，只能用Object类，里面的方法可以随便定义,然后直接调用该方法
        //这个相当精髓
        new Object() {
            void g() {
                System.out.println(item);
                item = "I'm changed by Inner";
                System.out.println(item);
                f();
            }
        }.g();
    }

    public static void main(String[] args) {
        SimpleClass simpleClass = new SimpleClass();
        simpleClass.changeFieldAndCallMethod();
    }
}
